package com.train.service.impl;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.train.common.ServerResponse;
import com.train.dao.UserMapper;
import com.train.pojo.User;
import com.train.service.IUserService;

@Service
public class UserServiceImpl implements IUserService {
	
	@Autowired
	private UserMapper userMapper;
	
	public ServerResponse addUser(User user, String openid) {
		User selectUser = userMapper.selectByPrimaryKey(openid);
		if(selectUser==null){
			user.setOpenid(openid);
			int insertUser = userMapper.insert(user);
			if(insertUser!=0){
				return ServerResponse.createBySuccess("添加用户成功", openid);
			}else{
				return ServerResponse.createByErrorMessage("添加用户失败");
			}
		}
		return ServerResponse.createBySuccess("用户已存在", openid);
	}

}
